<template>
  <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
    <div class="Logout">
      <Logout>退出</Logout>
    </div>
    <h1>添加仓库信息</h1>
    <el-form-item label="仓库id" prop="id">
      <el-input style="width: 800px" v-model="ruleForm.id" placeholder="请输入仓库编号" prefix-icon="el-icon-price-tag" maxlength="10" show-word-limit clearable></el-input>
    </el-form-item>
<!--    <el-form-item label="课程名" prop="name">-->
<!--      <el-input style="width: 800px" v-model="ruleForm.name" placeholder="请输入课程名" prefix-icon="el-icon-coordinate" maxlength="50" show-word-limit clearable></el-input>-->
<!--    </el-form-item>-->
    <el-form-item label="可入库时间" prop="number">
      <el-input style="width: 800px" v-model="ruleForm.number" placeholder="请输入入库时间" prefix-icon="el-icon-tickets" maxlength="10" show-word-limit clearable></el-input>
    </el-form-item>
    <el-form-item label="可存放时长" prop="time">
      <el-input style="width: 800px" v-model="ruleForm.time" placeholder="请输入可存放时长" prefix-icon="el-icon-date" maxlength="10" show-word-limit clearable></el-input>
    </el-form-item>
    <el-form-item label="仓储费用" prop="le">
      <el-input style="width: 800px" v-model="ruleForm.le" placeholder="请输入存储费用" prefix-icon="el-icon-coin" maxlength="10" show-word-limit clearable></el-input>
    </el-form-item>
    <el-form-item label="所在地" prop="address">
      <el-input style="width: 800px" v-model="ruleForm.address" placeholder="请输入场地所在地址" prefix-icon="el-icon-location" maxlength="50" show-word-limit clearable></el-input>
    </el-form-item>
<!--    <el-form-item label="教师号" prop="ID">-->
<!--      <el-input style="width: 800px" v-model="ruleForm.ID" placeholder="请输入教师编号" prefix-icon="el-icon-s-check" maxlength="10" show-word-limit clearable></el-input>-->
<!--    </el-form-item>-->
    <el-form-item label="仓库容量" prop="p">
      <el-input style="width: 800px" v-model="ruleForm.p" placeholder="请输入场地容量" prefix-icon="el-icon-star-off" maxlength="5" show-word-limit clearable></el-input>
    </el-form-item>
    <el-form-item label="已用量" prop="num">
      <el-input style="width: 800px" v-model="ruleForm.num" placeholder="请输入课程已使用容量" prefix-icon="el-icon-star-on" maxlength="5" show-word-limit clearable></el-input>
    </el-form-item>

    <el-form-item>
      <el-button type="success" @click="submitForm('ruleForm')" icon="el-icon-check">提交</el-button>
      <el-button type="danger" @click="resetForm('ruleForm')" icon="el-icon-refresh">重置</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
import Logout from "./Logout";
export default {
  name: "AddWarehouse",
  components:{Logout},
  data() {
    return {
      ruleForm : {
        id : '',
        // name : '',
        number: '',
        time: '',
        le:'',
        address:'',
        // ID:'',
        p:'',
        num:'',
      },
      rules : {
        id:
          {required: true, message: '请输入仓库id', trigger: 'blur'},

        // name:
          // {required: true, message: '请输入课程名', trigger: 'blur'},

        number:
          {required: true, message: '请输入可入库时间', trigger: 'blur'},

        time:
          {required: true, message: '请输入可存放时长', trigger: 'blur'},

        le:
          {required: true, message: '请输入仓储费用', trigger: 'blur'},
        address:
          {required: true, message: '请输入场地所在地址', trigger: 'blur'},
        // ID:
          // {required: true, message: '请输入教师号', trigger: 'blur'},
        p:
          {required: true, message: '请输入仓库容量', trigger: 'blur'},
        num:
          {required: true, message: '请输入已使用容量', trigger: 'blur'},
      },
    }
  },
  methods : {
    submitForm(formName) {
      const _this=this
      this.$refs[formName].validate((valid) => {
        if (valid) {
          console.log(_this.ruleForm)
          const params = {
            cno:_this.ruleForm.id,
            // cname:_this.ruleForm.name,
            cclasstime:_this.ruleForm.number,
            ccycle:_this.ruleForm.time,
            camount:_this.ruleForm.le,
            caddress:_this.ruleForm.address,
            // tno:_this.ruleForm.ID,
            cneed:_this.ruleForm.p,
            cjoin:_this.ruleForm.num
          }
          this.$axios.post(`/InsertCourse`,params).then((res) => {
            console.log(res);
            if (res.data.msg=="添加仓库成功"){
              alert("添加仓库成功");
            } else {
              alert(res.data.msg);
            }
          });
        }
        else {
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  }
}
</script>

<style scoped>

</style>
